#!/usr/bin/python
#coding:utf-8
'''
系统工具类
'''

import os,sys

curPath = os.path.abspath(os.path.dirname(__file__))
print('当前目录',curPath)

def dealCommand(command):
    '''
    执行命令
    args：
        command：命令
    return：
        命令处理后列表
    '''
    # log.info(command)
    output = os.popen(command)
    result=output.readlines()
    result =[line.strip() for line in result]
    return result


def runString(comm):
    '''
    执行系统命令，返回字符串
    '''
    r = os.popen(comm)
    msg=r.read()
    r.close()
    return msg


def timeout_command(command, timeout):
    '''
    执行系统命令
        command：命令
        timeout:超时时间，单位秒
    ''' 
    import subprocess, datetime, os, time, signal 
    cmd = command.split(" ") 
    start = datetime.datetime.now() 
    process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 
    while process.poll() is None: 
        time.sleep(0.2) 
        now = datetime.datetime.now() 
        if (now - start).seconds> timeout: 
            os.kill(process.pid, signal.SIGKILL) 
            os.waitpid(-1, os.WNOHANG) 
            return None 
    return process.stdout.readlines()

def checkVersion():
        #python版本
    version=0  #0 python3 1 python2
    if sys.version_info < (3, 0):
        version=1
    print(version,"0:python3 1:python2")

checkVersion()
print("用户工作空间",os.getenv("userprofile"))